package com.dyc.caradvertisting.ui.fmt.tab.store.VH;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dyc.caradvertisting.R;
import com.dyc.caradvertisting.bean.resp.GoodsBean;
import com.dyc.caradvertisting.event.StartBrotherEvent;
import com.dyc.caradvertisting.ui.fmt.tab.store.gd.GoodsDFmt;
import com.njh.tools.api.manager.RetrofitManager;
import com.njh.tools.base.BaseViewHolder;
import com.njh.tools.common.img.GlideUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by niejiahuan on 15/1/1.
 */

public class GoodsVH extends BaseViewHolder<GoodsBean> {

    public GoodsVH(View v) {
        super(v);
    }

    GoodsBean goodsBean;

    @Override
    public int getType() {
        return R.layout.itme_goods_list;
    }

    @Override
    public void onBindViewHolder(View view, GoodsBean obj) {
        ViewHolder viewHolder = new ViewHolder(view);
        goodsBean = obj;
        GlideUtils.displayImage(view.getContext(), RetrofitManager.baseUrl + obj.getSrc(), viewHolder.imgAdv);
        setTextValue(viewHolder.tvTitle, obj.getName());
        setTextValue(viewHolder.tvJq, "¥" + obj.getPrice());
        setTextValue(viewHolder.tvNumber, obj.getBuy() + "人购买");
        viewHolder.rtGoodsd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 这里我使用EventBus通知父MainFragment处理跳转(接耦),
                EventBus.getDefault().post(new StartBrotherEvent(GoodsDFmt.newInstance(goodsBean.getId())));
            }
        });

    }

    class ViewHolder {
        @BindView(R.id.img_adv)
        ImageView imgAdv;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_jq)
        TextView tvJq;
        @BindView(R.id.tv_number)
        TextView tvNumber;
        @BindView(R.id.rt_goodsd)
        LinearLayout rtGoodsd;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
